package com.example.onlineeducation.widget.marquee

import android.view.View
import com.example.onlineeducation.R
import com.yc.jetpacklib.extension.ycIsNotEmpty

open class MarqueeAdapter<Data> {
    private var mDataList: List<Data>? = null
    fun setDataList(dataList: List<Data>) {
        this.mDataList = dataList
    }

    var mItemClick: ((item: Data) -> Unit)? = null
    fun bind(view: View?, position: Int) {
        if (mDataList.ycIsNotEmpty()) {
            onBind(view, position, mDataList!![position])
            view?.setOnClickListener {
                mItemClick?.invoke(mDataList!![position])
            }
        }
    }

    protected open fun onBind(view: View?, position: Int, data: Data) {}
    fun getItemLayoutId(position: Int): Int {
        return R.layout.marquee_item
    }

    val itemCount: Int
        get() = if (mDataList == null) 0 else mDataList!!.size
}